﻿#ifndef CLEARPATHDB_H
#define CLEARPATHDB_H

#include <QSqlDatabase>
using namespace std;

#pragma pack(push,1)
struct ClearPath{
    int id;
    char path[256];
    bool is_filter_suffix;//是否过滤后缀
    char filter_suffix[256];//空为所有，多个后缀分号隔开
    bool cascade;//是否包含子文件夹
    bool data_number_enable;//数据量使能
    int  data_number;//数据量
    int unit_option;//数据量单位选项
    bool time_enable;//时间使能
    long elapsed;//时差 秒级
    int time_option;//基于时间选项
    bool enable;
    ClearPath(){
        memset(this,0,sizeof (ClearPath));
        is_filter_suffix = false;
    }
    void setPath(string str){
        memset(path,0,256);
        memcpy(path,str.c_str(),str.length() < 256 ? str.length() : 256);
    }
    void setFilterSuffix(string str){
        memset(filter_suffix,0,256);
        memcpy(filter_suffix,str.c_str(),str.length() < 256 ? str.length() : 256);
        is_filter_suffix = str.length() > 0;
    }
};
#pragma pack(pop)

class ClearPathDB
{
public:
    ClearPathDB();
    ~ClearPathDB();

    void openDataBase();
    void closeDataBase();
    QSqlDatabase getDataBase() const;
public:
    QList<ClearPath> getClearPathList();
    void addClearPath(ClearPath clearPath);
    void upClearPath(ClearPath clearPath);
private:
    QSqlDatabase dataBase;
    QString dbPath;
};

#endif // CLEARPATHDB_H
